﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<meta name="robots" content="noindex, nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script>forceNoScript = true;</script>
<script src="static/content.js" type="text/javascript"></script>
</head>
<body>
<p>搜索...</p>
<p id="container" style="display:none"></p>
<script>
/*
Usage: search.htm?q=query&m=mode

  mode = 1 -> index tab
  mode = 2 -> search tab

&m=mode is optional and defaults to mode #1 (index).
*/
var pQuery = getUrlParameter("q");
var pMode = (Number(getUrlParameter("m")) || 1);

switch(pMode) {
  case 1:
  cache.index_input = pQuery;
  cache.index_scrollPos = null;
  cache.clickTab = 1;
  loadScript(index.dataPath, function() {
    cache.index_data = indexData;
    document.getElementById('container').innerHTML = index.create(cache.index_data, -1);
    var aList = $('#container').children();
    match = index.findMatch(aList, pQuery.toLowerCase());
    if (match.length) {
      cache.index_clickItem = match.index();
      window.location = match.attr('href');
    }
    else {
      window.location = scriptDir+"/../";
    }
    cache.save();
  });
  break;
  case 2:
  cache.search_input = pQuery;
  cache.search_scrollPos = null;
  cache.clickTab = 2;
  cache.LastUsedSource = "search";
  loadScript(search.dataPath, function() {
    cache.search_index = SearchIndex;
    cache.search_files = SearchFiles;
    cache.search_titles = SearchTitles;
    cache.search_data = search.create(pQuery.toLowerCase());
    document.getElementById('container').innerHTML = cache.search_data;
    var aList = $('#container').children();
    if (aList.length)
      window.location = aList.eq(0).attr('href');
    else {
      window.location = scriptDir+"/../";
    }
    cache.save();
  });
  break;
}
// https://stackoverflow.com/a/21903119
function getUrlParameter(sParam) {
    var sPageURL, sParameterName, i;
    if (window.location.search)
      sPageURL = window.location.search.substring(1);
    else
      sPageURL = window.location.hash.substring(1);
    var sURLVariables = sPageURL.split('&');
    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split('=');

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
        }
    }
};
</script>
</body>
</html>